<?php
/*********************/
/*                   */
/*  Version : 5.1.0  */
/*  Author  : RM     */
/*  Comment : 071223 */
/*                   */
/*********************/

define( "JIEQI_MODULE_NAME", "system" );
require_once( "../global.php" );
include_once( JIEQI_ROOT_PATH."/class/power.php" );
$power_handler =& jieqipowerhandler::getinstance( "JieqiPowerHandler" );
$power_handler->getsavedvars( "system" );
jieqi_checkpower( $jieqiPower['system']['adminuser'], $jieqiUsersStatus, $jieqiUsersGroup, false, true );
jieqi_getconfigs( JIEQI_MODULE_NAME, "configs" );
if ( empty( $_REQUEST['page'] ) || !is_numeric( $_REQUEST['page'] ) )
{
		$GLOBALS['_REQUEST']['page'] = 1;
}
include_once( JIEQI_ROOT_PATH."/admin/header.php" );
include_once( JIEQI_ROOT_PATH."/class/online.php" );
$online_handler =& jieqionlinehandler::getinstance( "JieqiOnlineHandler" );
if ( isset( $_REQUEST['action'], $_REQUEST['sid'] ) )
{
		$mysid = session_id( );
		@session_id( $_REQUEST['sid'] );
		@session_destroy( );
		@session_id( $mysid );
		$criteria = new criteriacompo( new criteria( "sid", $_REQUEST['sid'], "=" ) );
		$online_handler->delete( $criteria );
		unset( $criteria );
}
$criteria = new criteriacompo( new criteria( "updatetime", JIEQI_NOW_TIME - $jieqiConfigs['system']['onlinetime'], ">" ) );
$allnum = $online_handler->getcount( $criteria );
$criteria->add( new criteria( "uid", "0" ), ">" );
if ( isset( $_REQUEST['username'], $_REQUEST['username'] ) )
{
		$criteria->add( new criteria( "uname", $_REQUEST['username'], "=" ) );
}
else if ( isset( $_REQUEST['groupid'], $_REQUEST['groupid'] ) )
{
		$criteria->add( new criteria( "groupid", $_REQUEST['groupid'], "=" ) );
}
$criteria->setsort( "updatetime" );
$criteria->setorder( "DESC" );
$criteria->setlimit( $jieqiConfigs['system']['useradminpnum'] );
$criteria->setstart( ( $_REQUEST['page'] - 1 ) * $jieqiConfigs['system']['useradminpnum'] );
$result = $online_handler->queryobjects( $criteria );
$userrows = array( );
$k = 0;
while ( $v = $online_handler->getobject( ) )
{
		$userrows[$k]['sid'] = $v->getvar( "sid" );
		$userrows[$k]['userid'] = $v->getvar( "uid" );
		$userrows[$k]['username'] = $v->getvar( "uname" );
		$userrows[$k]['name'] = $v->getvar( "name" );
		if ( strlen( $userrows[$k]['name'] ) == 0 )
		{
				$userrows[$k]['name'] = $userrows[$k]['username'];
		}
		$userrows[$k]['group'] = $jieqiGroups[$v->getvar( "groupid" )];
		$userrows[$k]['email'] = $v->getvar( "email" );
		$userrows[$k]['logintime'] = date( JIEQI_TIME_FORMAT, $v->getvar( "logintime" ) );
		$userrows[$k]['updatetime'] = date( JIEQI_TIME_FORMAT, $v->getvar( "updatetime" ) );
		$userrows[$k]['operate'] = $v->getvar( "operate" );
		$userrows[$k]['ip'] = $v->getvar( "ip" );
		$userrows[$k]['browser'] = $v->getvar( "browser" );
		$userrows[$k]['os'] = $v->getvar( "os" );
		$userrows[$k]['location'] = $v->getvar( "location" );
		++$k;
}
$jieqiTpl->assign_by_ref( "userrows", $userrows );
$rowcount = $online_handler->getcount( $criteria );
$jieqiTpl->assign_by_ref( "rowcount", $rowcount );
include_once( JIEQI_ROOT_PATH."/lib/html/page.php" );
$jumppage = new jieqipage( $rowcount, $jieqiConfigs['system']['useradminpnum'], $_REQUEST['page'] );
$jumppage->setlink( "", true, false );
$jieqiTpl->assign( "url_jumppage", $jumppage->whole_bar( ) );
$jieqiTpl->setcaching( 0 );
$jieqiTset['jieqi_contents_template'] = JIEQI_ROOT_PATH."/templates/admin/online.html";
include_once( JIEQI_ROOT_PATH."/admin/footer.php" );
?>
